#pragma once

/*
	File:	D3DManager.h
	Author:	TJ Ashby
	
	Comments:	Sets up Direct X for our game.
*/

#include <Windows.h>

#include "DirectX.h"

class TextureManager;
class ModelManager;
class ShaderManager;

class D3DManager
{
	friend class TextureManager;
	friend class ModelManager;
	friend class ShaderManager;

	D3DManager();
	~D3DManager(void);

	// Window Size
	unsigned wndWidth;
	unsigned wndHeight;
	// Windows
	HINSTANCE hInstance;
	HWND	hwnd;
	MSG		msg;
	WNDPROC wndProc;

	// Direct X
	IDirect3DDevice9 *d3dDevice;
	IDirect3D9		 *d3dObject;
	D3DPRESENT_PARAMETERS d3dpp;
	ID3DXLine *d3dLine;
	Matrix proj;

public:
	static D3DManager* getInstance();

	// Set up, run and then release all memory for Direct X
	void Initialize(HINSTANCE hInst,HWND hWnd,String Title,WNDPROC WndProc,unsigned WindowWidth,unsigned WindowHeight,bool Fullscreen = false,int ShowCmd = SW_SHOW);
	bool Running();
	void Shutdown();
	void CloseWindow();

	void Clear(Color &color);
	void Begin();
	void End();
	void Present();
	
	void DrawLine(const Vector2 *Points,unsigned PointCount,Color color);
	void DrawLine(const Vector2 &Point1,const Vector2 &Point2,Color color);
	void DrawRectangle(float left,float top,float right,float bottom,Color &BorderColor,Color &FillColor,float BorderWidth);
	void DrawRectangle(const RECT &rect,Color &BorderColor,Color &FillColor,float BorderWidth);
	void DrawTriangle(Vector2 &Point1,Vector2 &Point2,Vector2 &Point3,Color &BorderColor,Color &FillColor,float BorderWidth);
	void DrawTriangle(Vector2 Points[3],Color &BorderColor,Color &FillColor,float BorderWidth);
	void DrawCircle(const Vector2 &Center,float Radius,unsigned short Sides = 30,Color &color = Color(1,1,1,1));
	void DrawCircle(const Vector2 &Center,float Radius1,float Radius2,unsigned short Sides,Color &color = Color(1,1,1,1));
	
	// Accessors and Mutators
	unsigned getWndWidth() const { return wndWidth; }
	void setWndWidth(unsigned val) { wndWidth = val; }
	unsigned getWndHeight() const { return wndHeight; }
	void setWndHeight(unsigned val) { wndHeight = val; }
	HINSTANCE getHINSTANCE() const { return hInstance; }
	HWND	  getHWND() const { return hwnd; }
	IDirect3DDevice9* getDevice() { return d3dDevice; };
};

